<template>
<div>
    <el-form :model="inputForm" ref="inputForm" v-loading="loading"   :disabled="formReadOnly"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="24">
            <el-form-item label="设备名称" prop="equipmentName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.equipmentName" placeholder="请填写设备名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="部件名称" prop="partsName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.partsName" placeholder="请填写部件名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="零件名称" prop="sparePartsName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparePartsName" placeholder="请填写零件名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="油品型号" prop="oilType"
                :rules="[
                 ]">
              <el-input v-model="inputForm.oilType" placeholder="请填写油品型号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="清洁度" prop="cleanliness"
                :rules="[
                 ]">
              <el-input v-model="inputForm.cleanliness" placeholder="请填写清洁度"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="运动粘度" prop="kinematicViscosity"
                :rules="[
                 ]">
              <el-input v-model="inputForm.kinematicViscosity" placeholder="请填写运动粘度"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="酸值" prop="acid"
                :rules="[
                 ]">
              <el-input v-model="inputForm.acid" placeholder="请填写酸值"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="水分" prop="water"
                :rules="[
                 ]">
              <el-input v-model="inputForm.water" placeholder="请填写水分"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="抗乳化" prop="emulsification"
                :rules="[
                 ]">
              <el-input v-model="inputForm.emulsification" placeholder="请填写抗乳化"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="凝点" prop="freezingPoint"
                :rules="[
                 ]">
              <el-input v-model="inputForm.freezingPoint" placeholder="请填写凝点"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="倾点" prop="pourPoint "
                :rules="[
                 ]">
              <el-input v-model="inputForm.pourPoint " placeholder="请填写倾点"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="责任人" prop="responsible.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.responsible.id" @getValue='(value) => {inputForm.responsible.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="检验人" prop="inspector.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.inspector.id" @getValue='(value) => {inputForm.inspector.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="是否异常" prop="isnormal"
                :rules="[
                 ]">
                    <el-radio-group v-model="inputForm.isnormal">
                        <el-radio v-for="item in $dictUtils.getDictList('yes_no')" :label="item.value" :key="item.id">{{item.label}}</el-radio>
                    </el-radio-group>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
</div>
</template>

<script>
  import UserSelect from '@/components/userSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        loading: false,
        inputForm: {
          id: '',
          isnormal: '',
          equipmentName: '',
          partsName: '',
          sparePartsName: '',
          oilType: '',
          cleanliness: '',
          kinematicViscosity: '',
          acid: '',
          water: '',
          emulsification: '',
          freezingPoint: '',
          pourPoint: '',
          responsible: {
            id: ''
          },
          inspector: {
            id: ''
          },
          remarks: ''
        }
      }
    },
    props: {
      businessId: {
        type: String,
        default: ''
      },
      formReadOnly: {
        type: Boolean,
        default: false
      }
    },
    components: {
      UserSelect
    },
    watch: {
      'businessId': {
        handler (newVal) {
          if (this.businessId) {
            this.init(this.businessId)
          } else {
            this.$nextTick(() => {
              this.$refs.inputForm.resetFields()
            })
          }
        },
        immediate: true,
        deep: false
      }
    },
    methods: {
      init (id) {
        if (id) {
          this.loading = true
          this.inputForm.id = id
          this.$nextTick(() => {
            this.$refs.inputForm.resetFields()
            this.$http({
              url: `/check/checkoiltestingprocess/checkOilTestingProcess/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.checkOilTestingProcess)
              this.loading = false
            })
          })
        }
      },
      // 表单提交
      saveForm (callback) {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/check/checkoiltestingprocess/checkOilTestingProcess/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              if (data && data.success) {
                callback(data.businessTable, data.businessId)
              }
            })
          }
        })
      }
    }
  }
</script>
